package tech.dongliang.system.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import tech.dongliang.common.controller.CommonController;
import tech.dongliang.common.enums.EBizError;
import tech.dongliang.common.response.CommonResponse;
import tech.dongliang.common.response.ErrorData;
import tech.dongliang.system.service.ISysRoleMenuService;

import java.util.ArrayList;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author xdzhang
 * @since 2019-01-18
 */
@RestController
@RequestMapping("/system/role")
public class SysRoleMenuController extends CommonController {
    @Autowired
    private ISysRoleMenuService roleMenuService;

    /**
     * 删除
     */
    @PostMapping("/saveMenus")
    @ResponseBody
    public CommonResponse<Boolean> save(@RequestParam("roleId") Integer roleId, @RequestParam("menuIds[]") ArrayList<Integer> menuIds) throws Exception {
        if (roleMenuService.saveRoleMenu(roleId, menuIds)) {
            return CommonResponse.success(true);
        }
        return CommonResponse.error(new ErrorData(EBizError.UNKNOWE_ERROR));
    }
}
